package com.jdls.tanhua.dubbo.utils;

import com.jdls.tanhua.mongo.Friend;
import com.jdls.tanhua.mongo.MovementTimeLine;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 嘉德罗斯
 * @date 2021/10/28
 */
@Component
public class TimeLineService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Async
    public void save(ObjectId id, List<Friend> friends){

        try {
            Thread.sleep(10000L);
        } catch (InterruptedException e) {
        }
        for (Friend friend : friends) {
            MovementTimeLine movementTimeLine = new MovementTimeLine();
            movementTimeLine.setMovementId(id);
            movementTimeLine.setUserId(friend.getUserId());
            movementTimeLine.setFriendId(friend.getFriendId());
            movementTimeLine.setCreated(System.currentTimeMillis());
            mongoTemplate.save(movementTimeLine);
        }

    }
}
